#!/bin/bash

set -e

# Deploy tar-files and checksums to the firehol website

if [ ! -f /tmp/ssh-key-loaded ]
then
  echo "No ssh key decrypted - skipping deployment to website"
  exit 0
fi

case "$TRAVIS_BRANCH" in
  master|stable-*)
    :
  ;;
  *)
    echo "Not on master or stable-* branch - skipping deployment to website"
    exit 0
  ;;
esac

if [ "$TRAVIS_PULL_REQUEST" = "true" ]
then
  echo "Building pull request - skipping deployment to website"
  exit 0
fi

if [ "$TRAVIS_TAG" != "" ]
then
  echo "Building tag - skipping deployment to website"
  exit 0
fi

if [ "$CC" != "gcc" ]
then
  echo "Building non-gcc version - skipping deployment to website"
  exit 0
fi

ssh-keyscan -H firehol.org >> ~/.ssh/known_hosts
ssh travis@firehol.org mkdir -p uploads/netdata/$TRAVIS_BRANCH/
scp -p *.tar.* travis@firehol.org:uploads/netdata/$TRAVIS_BRANCH/
ssh travis@firehol.org touch uploads/netdata/$TRAVIS_BRANCH/complete.txt
